﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataManager;
using HRMS_Model;
using HRMS.Models;


namespace HRMS.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/
        //readonly User _model = new User
        //{
        //    UsrRoles = RoleModels.GetRoles().ToList()
           
        //};

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(User loggedInuser)
        {
            if (UserManager.ValidateUser(loggedInuser.UserName, loggedInuser.Password))
            {
                return RedirectToAction("Index", "Home");
            }
            return View(loggedInuser);
        }

        [HttpGet]
        public ActionResult AddUser()
        {
          //  return View(_model);
            return View();
        }

        [HttpPost]
        public ActionResult AddUser(User user)
        {
            if(ModelState.IsValid)
            {
                var usr = new User
                {
                    UserName=user.UserName,
                    Password=user.Password,
                    RoleId=user.RoleId,
                    Active=user.Active
                };
                Users.AddUser(usr);
                return RedirectToAction("AddUser", "User");
            }

           // return View(_model);
            return View();
        }

    }
}
